class MessageView extends eui.Component implements  eui.UIComponent {
	public titleLbl:eui.Label;
	public okBtn:eui.Button;
	public okBtn2:eui.Button;
	public cancelBtn:eui.Button;
	public msgText:eui.EditableText;

	private title:string;
	private msg:string;
	private hasCancelBtn:boolean;
	private okFunction:Function;
	private okFunctionObj:any;

	public constructor(title:string, msg:string, hasCancelBtn:boolean, okFunction:Function = null, okFunctionObj?:any) {
		super();

		this.title = title;
		this.msg = msg;
		this.hasCancelBtn = hasCancelBtn;
		this.okFunction = okFunction;
		this.okFunctionObj = okFunctionObj;

		this.addEventListener(eui.UIEvent.COMPLETE, this.onComplete, this);
		this.skinName = "resource/game/MessageView.exml";
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
	}

	private onComplete()
	{
		this.init();
	}

	private init()
	{
		this.titleLbl.text = this.title;
		this.msgText.text = this.msg;
		this.msgText.height = this.msgText.textHeight;
		if (this.hasCancelBtn)
		{
			this.okBtn.visible = true;
			this.cancelBtn.visible = true;
			this.okBtn2.visible = false;
		}
		else
		{
			this.okBtn.visible = false;
			this.cancelBtn.visible = false;
			this.okBtn2.visible = true;
		}

		this.okBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOkbtn, this);
		this.okBtn2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOkbtn, this);
		this.cancelBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onCancelBtn, this);
	}

	private onOkbtn()
	{
		if (this.okFunction)
			this.okFunction.apply(this.okFunctionObj);
		
		this.parent.removeChild(this);
	}

	private onCancelBtn()
	{
		this.parent.removeChild(this);
	}
	
}